<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
    </ma-crud>
  </div>
</template>
<script setup>
import {ref, reactive} from 'vue'
import baseModel from '@/api/backend/baseModel.js'
import {Message} from '@arco-design/web-vue'
import tool from '@/utils/tool.js'
import * as common from '@/utils/common.js'

const crudRef = ref()


const numberOperation = (newValue, id, numberName) => {
  baseModel.numberOperation({id, numberName, numberValue: newValue}).then(res => {
    res.success && Message.success(res.message)
  }).catch(e => {
    console.log(e)
  })
}

const switchStatus = (statusValue, id, statusName) => {
  baseModel.changeStatus({id, statusName, statusValue}).then(res => {
    res.success && Message.success(res.message)
  }).catch(e => {
    console.log(e)
  })
}


const options = reactive({
  id: 'base_model',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationColumnWidth: 160,
  formOption: {
    viewType: 'drawer',
    width: 600
  },
  api: baseModel.getList,
  recycleApi: baseModel.getRecycleList,
  add: {
    show: true,
    api: baseModel.save,
    auth: ['base:model:save']
  },
  edit: {
    show: true,
    api: baseModel.update,
    auth: ['base:model:update']
  },
  delete: {
    show: true,
    api: baseModel.deletes,
    auth: ['base:model:delete'],
    realApi: baseModel.realDeletes,
    realAuth: ['base:model:realDeletes']
  },
  recovery: {
    show: true,
    api: baseModel.recoverys,
    auth: ['base:model:recovery']
  }
})

const columns = reactive([
  {
    title: "ID",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    showTime: true,
    hide: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    showTime: true,
    hide: true
  },
  {
    title: "删除时间",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "模型名称",
    dataIndex: "name",
    formType: "input",
    search: true
  },
  {
    title: "调用标识",
    dataIndex: "code",
    formType: "input",
  },
  {
    title: "排序",
    dataIndex: "sort",
    formType: "input-number"
  },
  {
    title: "状态",
    dataIndex: "status",
    formType: "switch",
    checkedValue: "1",
    uncheckedValue: "2"
  },
  {
    title: "类型",
    dataIndex: "type",
    formType: "select",
    multiple: false,
    dict: {
      data: [
        {
          label: "行业",
          value: "1"
        },
        {
          label: "项目",
          value: "2"
        }
      ],
      translation: true
    }
  },
  {
    title: '配置部门', dataIndex: 'dept', search: true, width: 220,
    formType: "select",
    multiple: true,
    dict: {
      remote: "base/dept/remote",
      openPage: false,
      props: {label: 'name', value: 'name'},
      remoteOption: {
        sort: {id: 'desc'},
        select: ['name']
      },
      translation: true
    },
    hide: true
  },
  {
    title: "配置职位",
    dataIndex: "post",
    formType: "select",
    multiple: true,
    dict: {
      remote: "base/post/remote",
      openPage: false,
      props: {label: 'name', value: 'name'},
      remoteOption: {
        sort: {id: 'desc'},
        select: ['name']
      },
      translation: true,
    },
    hide: true
  },
  {
    title: "配置专业",
    dataIndex: "major",
    formType: "select",
    multiple: true,
    dict: {
      remote: "base/major/remote",
      openPage: false,
      props: {label: 'name', value: 'name'},
      remoteOption: {
        sort: {id: 'desc'},
        select: ['name']
      },
      translation: true
    },
    hide: true
  },
  {
    title: "配置组织",
    dataIndex: "organize",
    formType: "select",
    multiple: true,
    dict: {
      remote: "base/organize/remote",
      openPage: false,
      props: {label: 'name', value: 'name'},
      remoteOption: {
        sort: {id: 'desc'},
        select: ['name']
      },
      translation: true
    },
    hide: true
  },
  {
    title: "配置插件",
    dataIndex: "plugin",
    formType: "select",
    multiple: true,
    dict: {
      remote: "backend/plugin/remote",
      openPage: false,
      props: {label: 'name', value: 'id'},
      remoteOption: {
        sort: {id: 'desc'},
        select: ['name','id']
      },
      translation: true
    },
    hide: true
  }
])
</script>
<script> export default {name: 'base:model'} </script>